<?php
class Model_Admin_Common extends Model{
    function create_uuid($prefix = ""){    //可以指定前缀
        $charid = strtoupper(md5(uniqid(mt_rand(), true)));
        $hyphen = chr(45);// "-"
        $uuid = chr(123)// "{"
            .substr($charid, 0, 8).$hyphen
            .substr($charid, 8, 4).$hyphen
            .substr($charid,12, 4).$hyphen
            .substr($charid,16, 4).$hyphen
            .substr($charid,20,12)
            .chr(125);// "}"
        return $uuid;
    }
    public function deleteInfo($tableName,$id){
       $sql="update  $tableName set isdeleted='1' where  $tableName"."id in($id)";
            $total_rows=DB::query(null,$sql)->execute();
            Database::instance()->commit();
            return json_encode(array("info"=>"success","count"=>$total_rows));
    }
    public  function  loadInfoById($sql){
        $data=DB::query(Database::SELECT,$sql)->execute()->as_array();
        return json_encode(array("list"=> $data));
    }
    public function upload_file($filepath,$upFilePath,$image=''){
        if(file_exists($filepath)){

            $result=move_uploaded_file($filepath,$upFilePath);

        }
        if($result==true){
            if (is_file($image)){
              unlink ($image);
            }
            return true;
        }else{
            return false;
        }
    }
}